export interface AgentMetrics {
  totalRequests: number;
  averageResponseTime: number;
  errorRate: number;
  intentDistribution: Record<string, number>;
  escalationCount: number;
}

export class AgentMonitor {
  private metrics: AgentMetrics = {
    totalRequests: 0,
    averageResponseTime: 0,
    errorRate: 0,
    intentDistribution: {},
    escalationCount: 0
  };

  private responseTimes: number[] = [];
  private errors: number = 0;

  recordRequest(intentType: string, responseTime: number, isError: boolean, escalated: boolean) {
    this.metrics.totalRequests++;
    this.responseTimes.push(responseTime);
    
    if (isError) {
      this.errors++;
    }
    
    if (escalated) {
      this.metrics.escalationCount++;
    }

    // 更新意图分布
    this.metrics.intentDistribution[intentType] = 
      (this.metrics.intentDistribution[intentType] || 0) + 1;

    // 更新平均响应时间
    const sum = this.responseTimes.reduce((a, b) => a + b, 0);
    this.metrics.averageResponseTime = sum / this.responseTimes.length;

    // 更新错误率
    this.metrics.errorRate = this.errors / this.metrics.totalRequests;
  }

  getMetrics(): AgentMetrics {
    return { ...this.metrics };
  }

  reset() {
    this.metrics = {
      totalRequests: 0,
      averageResponseTime: 0,
      errorRate: 0,
      intentDistribution: {},
      escalationCount: 0
    };
    this.responseTimes = [];
    this.errors = 0;
  }
}



























